#include <iostream>
#include <thread>
#include <mutex>

using namespace std;

int gvar = 5;
mutex gm;

void threadFunc1()
{
	gm.lock();
	gvar = 10;
	cout << "thread func1-1, gvar = " << gvar << endl;
	if(1) {
		gm.unlock();
		return;
	}
	cout << "thread func1-2, gvar = " << gvar << endl;
	gm.unlock();
}

void threadFunc2()
{
	gm.lock();
	cout << "thread func2, gvar = " << gvar << endl;
	gm.unlock();
}

int main()
{
	thread t1(&threadFunc1), t2(threadFunc2);
	t1.join();
	t2.join();

	return 0;
}